<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>基本信息</title>
    <%@include file="/WEB-INF/pages/common/taglib.jsp" %>
    <%@include file="/WEB-INF/pages/common/common.jsp" %>
    <style>
        .table3 tr {
            height: 40px;
            line-height: 40px;
            border: 1px #ccc solid
        }
    </style>
</head>
<body style="overflow-x: hidden">
<div class="content content_frame">
    <h4 class="mainTitle"><img src="${basePath}/images/icon3.png"/>报核状态:
        <span style="cursor: pointer"
              id="sendStatusC">${empty baseInfo.sendStatusDisplay ? '暂无' : baseInfo.sendStatusDisplay}</span>
    </h4>
    <br/>
    <ul class="contentNav dib-wrap">
        <li class="dib" onclick="saveBaseInfo()">
            <a>
                <i class='fa fa-save'></i>&nbsp;&nbsp;保&nbsp;存 </a>
        </li>
        <li class="dib">
            <a onclick="javascript:history.go(-1)">
                <i class='fa fa-reply'></i>&nbsp;&nbsp;返&nbsp;回 </a>
        </li>
    </ul>
    <br/>

    <form id="baseForm">
        <input type="hidden" name="id" value="${baseInfo.id}">
        <input type="hidden" name="sendStatus" value="${baseInfo.sendStatus}">
        <table class="table3">
            <tr>
                <th colspan="4">基本信息</th>
            </tr>
            <tr>
                <td width="15%">手册编号</td>
                <td width="35%">
                    <label><input type="text" name="eBillingNo"
                                  value="${baseInfo.eBillingNo}"></label>
                </td>
                <td width="15%">企业内部编码</td>
                <td width="35%">
                    <label><input type="text" name="entEBillingNo"
                                  value="${baseInfo.entEBillingNo}"></label>
                </td>
            </tr>
            <tr>
                <td width="15%">经营单位</td>
                <td width="35%">
                    <label><input type="text" name="enterpriseName"
                                  value="${baseInfo.enterpriseName}"></label>
                </td>
                <td width="15%">报核类型</td>
                <td width="35%">
                    <label><input type="text" name="decType"
                                  value="电子手册正式报核" readonly="readonly"></label>
                </td>
            </tr>
            <tr>
                <td width="15%">进口总金额</td>
                <td width="35%">
                    <label><input type="text" name="importTotalValue"
                                  value="${baseInfo.importTotalValue}"></label>
                </td>
                <td width="15%">出口总金额</td>
                <td width="35%">
                    <label><input type="text" name="exportTotalValue"
                                  value="${baseInfo.exportTotalValue}"></label>
                </td>
            </tr>
            <tr>
                <td width="15%">进口报关单份数</td>
                <td width="35%">
                    <label><input type="text" name="importTotalDeclareNum"
                                  value="${baseInfo.importTotalDeclareNum}"></label>
                </td>
                <td width="15%">出口报关单份数</td>
                <td width="35%">
                    <label><input type="text" name="exportTotalDeclareNum"
                                  value="${baseInfo.exportTotalDeclareNum}"></label>
                </td>
            </tr>
            <tr>
                <td width="15%">报核料件份数</td>
                <td width="35%">
                    <label><input type="text" name="cancelMaterialsNum"
                                  value="${baseInfo.cancelMaterialsNum}"></label>
                </td>
                <td width="15%">报核成品项数</td>
                <td width="35%">
                    <label><input type="text" name="cancelEndgoodNum"
                                  value="${baseInfo.cancelEndgoodNum}"></label>
                </td>
            </tr>
            <tr>
                <td width="15%">申报日期</td>
                <td width="35%">
                    <label><input type="text" name="declDate"
                                  value="${baseInfo.declDate}" class="Wdate"
                                  onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"></label>
                </td>
                <td width="15%">录入员代码</td>
                <td width="35%">
                    <label><input type="text" name="createOperId"
                                  value="${baseInfo.createOperId}"></label>
                </td>
            </tr>
        </table>
    </form>
    <br/>

    <form id="declareForm">
        <input type="hidden" name="id" value="${declare.id}">
        <input type="hidden" name="relateId" value="${declare.relateId}">
        <table class="table3">
            <tr>
                <th colspan="4">报关单信息</th>
            </tr>
            <tr>
                <td width="15%">报关单号</td>
                <td width="35%">
                    <label><input type="text" name="declNo"
                                  value="${declare.declNo}"></label>
                </td>
                <td width="15%">申报地海关</td>
                <td width="35%">
                    <label> <ui:tsingletableautocomplete
                            keyFieldName="declCustomId"
                            valueFieldName="declCustomIdXXX"
                            tableName="S_Customs_eport"
                            key="CUSTOMS_CODE"
                            value="CUSTOMS_NAME"
                            relateKeyFieldName=""
                            relateValueFieldName=""
                            defaultKey="${declare.declCustomId}"
                            defaultValue=""
                            /></label>
                </td>
            </tr>
            <tr>
                <td width="15%">进出口标志</td>
                <td width="35%">
                    <label><ui:tsingletableautocomplete
                            keyFieldName="ieFlag"
                            valueFieldName="ieFlagXXXX"
                            tableName="DICT_ITEM"
                            key="ITEM_KEY"
                            value="ITEM_VALUE"
                            groupId="ieType"
                            defaultKey="${declare.ieFlag}"
                            defaultValue=""/></label>
                </td>
                <td width="15%">申报日期</td>
                <td width="35%">
                    <label><input type="text" name="declDate"
                                  value="${declare.declDate}" class="Wdate"
                                  onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"></label>
                </td>
            </tr>
            <tr>
                <td width="15%">进出口日期</td>
                <td width="35%">
                    <label><input type="text" name="ieDate"
                                  value="${declare.ieDate}" class="Wdate"
                                  onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"></label>
                </td>
                <td width="15%">核扣方式</td>
                <td width="35%">
                    <label><input type="text" name="verifyMode"
                                  value="${declare.verifyMode}"></label>
                </td>
            </tr>
        </table>
    </form>
    <br/>
    <ul class="contentNav dib-wrap">
        <li class="dib" onclick="save(saveDeclareInfo,'declareForm')">
            <a>
                <i class='fa fa-save'></i>&nbsp;&nbsp;保&nbsp;存 </a>
        </li>
    </ul>
    <br/>

    <table id="declareList" style="height: 1px"></table>
    <div id="declarePage"></div>
    <br/>

    <form id="endgoodsForm">
        <input type="hidden" name="id" value="${endgoods.id}">
        <input type="hidden" name="relateId" value="${endgoods.relateId}">
        <table class="table3">
            <tr>
                <th colspan="4">成品信息</th>
            </tr>
            <tr>
                <td width="15%">成品序号</td>
                <td width="35%">
                    <label><input type="text" name="seqNo"
                                  value="${endgoods.seqNo}"></label>
                </td>
                <td width="15%">商品编码</td>
                <td width="35%">
                    <label><input type="text" name="goodsNo" id="endgoodsHscode"
                                  value="${endgoods.goodsNo}">
                        <script type="text/javascript">
                            getHsCode({
                                "id": "endgoodsHscode",
                                "decType": "1",
                                "codeS": "endgoodsCodeS",
                                "goodsName": "endgoodsGoodsName"
                            });
                            $("#endgoodsHscode_input").data("text", '${endgoods.goodsNo}').val('${endgoods.goodsNo}');
                        </script>
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">附加编号</td>
                <td width="35%">
                    <label><input type="text" name="addNo" id="endgoodsCodeS" readonly="readonly"
                                  value="${endgoods.addNo}"></label>
                </td>
                <td width="15%">商品名称</td>
                <td width="35%">
                    <label><input type="text" name="goodsName" id="endgoodsGoodsName"
                                  value="${endgoods.goodsName}">
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">计量单位</td>
                <td width="35%">
                    <label><ui:tautocomplete keyFieldName="unit"
                                             valueFieldName="unitXXX"
                                             tableName="S_NUM_UNIT_E"
                                             custInspFlag="C"
                                             relateKeyFieldName=""
                                             relateValueFieldName=""
                                             defaultKey="${endgoods.unit}"
                                             defaultValue=""
                            /></label>
                </td>
                <td width="15%">出口总数量</td>
                <td width="35%">
                    <label><input type="text" name="exportTotalQty"
                                  value="${endgoods.exportTotalQty}">
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">深加工结转出口数量</td>
                <td width="35%">
                    <label><input type="text" name="exportDeepProcessQty"
                                  value="${endgoods.exportDeepProcessQty}"></label>
                </td>
                <td width="15%">产品放弃数量</td>
                <td width="35%">
                    <label><input type="text" name="prodAbandonQty"
                                  value="${endgoods.prodAbandonQty}">
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">成品退换进口数量</td>
                <td width="35%">
                    <label><input type="text" name="prodReturnImportQty"
                                  value="${endgoods.prodReturnImportQty}"></label>
                </td>
                <td width="15%">产品退换出口数量</td>
                <td width="35%">
                    <label><input type="text" name="prodReturnExportQty"
                                  value="${endgoods.prodReturnExportQty}">
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">企业库存量</td>
                <td width="35%">
                    <label><input type="text" name="entStockQty"
                                  value="${endgoods.entStockQty}"></label>
                </td>
                <td></td>
                <td></td>
            </tr>
        </table>
    </form>

    <br/>
    <ul class="contentNav dib-wrap">
        <li class="dib" onclick="save(saveEndgoodsInfo,'endgoodsForm')">
            <a>
                <i class='fa fa-save'></i>&nbsp;&nbsp;保&nbsp;存 </a>
        </li>
    </ul>
    <br/>
    <table id="endgoodList" style="height: 1px">
    </table>
    <div id="endgoodPage">
    </div>

    <br/>

    <form id="materialsForm">
        <input type="hidden" name="id" value="${materials.id}">
        <input type="hidden" name="relateId" value="${materials.relateId}">
        <table class="table3">
            <tr>
                <th colspan="4">料件信息</th>
            </tr>
            <tr>
                <td width="15%">料件序号</td>
                <td width="35%">
                    <label><input type="text" name="seqNo"
                                  value="${materials.seqNo}"></label>
                </td>
                <td width="15%">商品编码</td>
                <td width="35%">
                    <label><input type="text" name="goodsNo" id="materialsHscode"
                                  value="${materials.goodsNo}">
                        <script type="text/javascript">
                            getHsCode({
                                "id": "materialsHscode",
                                "decType": "1",
                                "codeS": "materialsCodeS",
                                "goodsName": "materialsGoodsName"
                            });
                            $("#materialsHscode_input").data("text", '${materials.goodsNo}').val('${materials.goodsNo}');
                        </script>
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">附加编号</td>
                <td width="35%">
                    <label><input type="text" name="addNo" id="materialsCodeS"  readonly="readonly"
                                  value="${materials.addNo}"></label>
                </td>
                <td width="15%">商品名称</td>
                <td width="35%">
                    <label><input type="text" name="goodsName" id="materialsGoodsName"
                                  value="${materials.goodsName}">
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">计量单位</td>
                <td width="35%">
                    <label><ui:tautocomplete keyFieldName="mUnit"
                                             valueFieldName="mUnitXXX"
                                             tableName="S_NUM_UNIT_E"
                                             custInspFlag="C"
                                             relateKeyFieldName=""
                                             relateValueFieldName=""
                                             defaultKey="${materials.mUnit}"
                                             defaultValue=""/>
                    </label>
                </td>
                <td width="15%">进口总数量</td>
                <td width="35%">
                    <label><input type="text" name="importQty"
                                  value="${materials.importQty}">
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">深加工结转进口数量</td>
                <td width="35%">
                    <label><input type="text" name="importDeepProcessQty"
                                  value="${materials.importDeepProcessQty}"></label>
                </td>
                <td width="15%">产品总耗用量</td>
                <td width="35%">
                    <label><input type="text" name="prodUseQty"
                                  value="${materials.prodUseQty}">
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">内销数量</td>
                <td width="35%">
                    <label><input type="text" name="domesticSaleQty"
                                  value="${materials.domesticSaleQty}"></label>
                </td>
                <td width="15%">复出数量</td>
                <td width="35%">
                    <label><input type="text" name="comebackQty"
                                  value="${materials.comebackQty}">
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">料件放弃数量</td>
                <td width="35%">
                    <label><input type="text" name="abandonQty"
                                  value="${materials.abandonQty}"></label>
                </td>
                <td width="15%">边角料数量</td>
                <td width="35%">
                    <label><input type="text" name="scrapQty"
                                  value="${materials.scrapQty}">
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">余料结转数量</td>
                <td width="35%">
                    <label><input type="text" name="leftCarryoverQty"
                                  value="${materials.leftCarryoverQty}"></label>
                </td>
                <td width="15%">料件剩余数量</td>
                <td width="35%">
                    <label><input type="text" name="leftQty"
                                  value="${materials.leftQty}">
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">企业库存数</td>
                <td width="35%">
                    <label><input type="text" name="entStockQty"
                                  value="${materials.entStockQty}"></label>
                </td>
                <td></td>
                <td></td>
            </tr>
        </table>
    </form>

    <br/>
    <ul class="contentNav dib-wrap">
        <li class="dib" onclick="save(saveMaterialsInfo,'materialsForm')">
            <a>
                <i class='fa fa-save'></i>&nbsp;&nbsp;保&nbsp;存 </a>
        </li>
    </ul>
    <br/>

    <table id="materialsList" style="height: 1px">
    </table>
    <div id="materialsPage"></div>
    <br/>

    <form id="consumptionForm">
        <input type="hidden" name="id" value="${consumption.id}">
        <input type="hidden" name="relateId" value="${consumption.relateId}">
        <table class="table3">
            <tr>
                <th colspan="4">单损耗信息</th>
            </tr>
            <tr>
                <td width="15%">成品序号</td>
                <td width="35%">
                    <label><input type="text" name="seqNo"
                                  value="${consumption.seqNo}"></label>
                </td>
                <td width="15%">成品名称</td>
                <td width="35%">
                    <label><input type="text" name="goodName"
                                  value="${consumption.goodName}">
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">料件序号</td>
                <td width="35%">
                    <label> <input type="text" name="materialsNo"
                                   value="${consumption.materialsNo}"></label>
                </td>
                <td width="15%">料件名称</td>
                <td width="35%">
                    <label><input type="text" name="materialsName"
                                  value="${consumption.materialsName}">
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">处理标志</td>
                <td width="35%">
                    <label><input type="text" name="dealFlag"
                                  value="${consumption.dealFlag}"></label>
                </td>
                <td width="15%">单耗/净耗</td>
                <td width="35%">
                    <label><input type="text" name="netWaste"
                                  value="${consumption.netWaste}">
                    </label>
                </td>
            </tr>
            <tr>
                <td width="15%">损耗率%</td>
                <td width="35%">
                    <label><input type="text" name="wasteRate"
                                  value="${consumption.wasteRate}"></label>
                </td>
                <td width="15%">非保税料件比例%</td>
                <td width="35%">
                    <label><input type="text" name="unTaxMaterialsPercent"
                                  value="${consumption.unTaxMaterialsPercent}">
                    </label>
                </td>
            </tr>
        </table>
    </form>

    <br/>
    <ul class="contentNav dib-wrap">
        <li class="dib" onclick="save(saveConsumptionInfo,'consumptionForm')">
            <a>
                <i class='fa fa-save'></i>&nbsp;&nbsp;保&nbsp;存 </a>
        </li>
    </ul>
    <br/>

    <table id="consumptionList" style="height: 1px">
    </table>
    <div id="consumptionPage"></div>

    <br/>
</div>

<script type="text/javascript">
    var nonEditable = {"3": "审核通过"}['${sendStatus}'];
    function ajaxDelete(url, data, callback) {
        $.ajax({
            url: url,
            type: "post",
            data: data,
            dataType: "json",
            success: function (result) {
                showOKMessage("删除成功！", "提示信息", null, null);
                if (typeof callback === "function") {
                    callback();
                }
            },
            error: function (error) {
                showErrorMessage("操作失败，请及时联系管理员，错误信息：" + error, "错误提示", null, null);
            }
        });
    }

    function ieFlag(cellvalue, options, rowObject) {
        return $._options._dictName($.trim(cellvalue || ''), {"I": "进口", "E": "出口"});
    }

    function deleteDeclare(id) {
        ajaxDelete($basePath + "/exportB2C/cancelBillDeclare/delete", {"id": id}, reloadDeclareGrid);
    }

    function deleteEndgood(id) {
        ajaxDelete($basePath + "/exportB2C/cancelBillEndgood/delete", {"id": id}, reloadEndgoodGrid);
    }

    function deleteMaterials(id) {
        ajaxDelete($basePath + "/exportB2C/cancelBillMaterials/delete", {"id": id}, reloadMaterialsGrid);
    }

    function deleteConsumption(id) {
        ajaxDelete($basePath + "/exportB2C/cancelBillConsumption/delete", {"id": id}, reloadConsumptionGrid);
    }

    function declareOptions(cellvalue, options, rowObject) {
        return "<a class=\"btn-link\" onclick=\"deleteDeclare('" + rowObject.id + "')\"\"><span style=\"color:#00acec\">删除</span></a>"
    }

    function endgoodOptions(cellvalue, options, rowObject) {
        return "<a class=\"btn-link\" onclick=\"deleteEndgood('" + rowObject.id + "')\"\"><span style=\"color:#00acec\">删除</span></a>";
    }

    function materialsOptions(cellvalue, options, rowObject) {
        return "<a class=\"btn-link\" onclick=\"deleteMaterials('" + rowObject.id + "')\"\"><span style=\"color:#00acec\">删除</span></a>";
    }

    function consumptionOptions(cellvalue, options, rowObject) {
        return "<a class=\"btn-link\" onclick=\"deleteConsumption('" + rowObject.id + "')\"\"><span style=\"color:#00acec\">删除</span></a>";
    }

    $(function () {
        $("input").addClass("input1");
        $(".table3 td:even").css("background-color", "#f5f5f5");

        $("#declareList").jqGrid({
            datatype: "json",
            url: $basePath + "/exportB2C/cancelBillDeclare/queryDeclareList",
            postData: {relateId: '${baseInfo.id}'},
            colNames: ['', '报关单号', '申报地海关', '进出口标志', '申报日期', '进出口日期', '核扣方式', '操作'],
            colModel: [
                {name: 'id', index: 'id', hidden: true},
                {name: 'declNo', index: 'declNo', width: 40},
                {name: 'declCustomId', index: 'declCustomId', width: 100},
                {name: 'ieFlag', index: 'ieFlag', width: 100, formatter: ieFlag},
                {name: 'declDate', index: 'declDate', width: 100},
                {name: 'ieDate', index: 'ieDate', width: 100},
                {name: 'verifyMode', index: 'verifyMode', width: 100},
                {
                    name: 'options',
                    index: 'options',
                    sortable: false,
                    width: 100,
                    hidden: nonEditable,
                    formatter: declareOptions
                }
            ],
//            caption: "报关单列表",
            viewrecords: true, // show the current page, data rang and total records on the toolbar
            height: 'auto',
            autowidth: true,
            shrinkToFit: false,
            autoScroll: true,
            rowNum: 10, //每页显示记录数
            rowList: [10, 20, 100], //可调整每页显示的记录数
            pager: "#declarePage", //分页工具栏
            sortname: "declDate",
            sortorder: "desc",
            loadComplete: function () {
                var rowNum = $(this).jqGrid('getGridParam', 'records');
                if (rowNum <= 0) {
                    if ($(this).parent().children('.norecords').length == 0)
                        $(this).parent().append("<div class=\"norecords\">暂无数据！</div>");
                    $(this).parent().children('.norecords').show();
                }
                else {//如果存在记录，则隐藏提示信息。
                    $(this).parent().children('.norecords').hide();
                }

                $(".ui-jqgrid tr.ui-row-ltr td").css('text-align', 'center');
            }
        });

        $("#endgoodList").jqGrid({
            datatype: "json",
            url: $basePath + "/exportB2C/cancelBillEndgood/queryEndGoodsList",
            postData: {relateId: '${baseInfo.id}'},
            colNames: ['', '序号', '商品编码', '附加号', '商品名称', '计量单位', '出口总数量', '深加工结转出口数量', '产品放弃数量',
                '成品退换进口数量', '产品退换出口数量', '企业库存量', '操作'],
            colModel: [
                {name: 'id', index: 'id', hidden: true},
                {name: 'seqNo', index: 'seqNo', width: 40},
                {name: 'goodsNo', index: 'goodsNo', width: 100},
                {name: 'addNo', index: 'addNo', width: 100},
                {name: 'goodsName', index: 'goodsName', width: 100},
                {name: 'unitDisplay', index: 'unitDisplay', width: 100},
                {name: 'exportTotalQty', index: 'exportTotalQty', width: 100},
                {name: 'exportDeepProcessQty', index: 'exportDeepProcessQty', width: 100},
                {name: 'prodAbandonQty', index: 'prodAbandonQty', width: 100},
                {name: 'prodReturnImportQty', index: 'prodReturnImportQty', width: 100},
                {name: 'prodReturnExportQty', index: 'prodReturnExportQty', width: 100},
                {name: 'entStockQty', index: 'entStockQty', width: 100},
                {
                    name: 'options',
                    index: 'options',
                    sortable: false,
                    width: 100,
                    hidden: nonEditable,
                    formatter: endgoodOptions
                }
            ],
//            caption: "成品列表",
            viewrecords: true, // show the current page, data rang and total records on the toolbar
            height: 'auto',
            autowidth: true,
            shrinkToFit: false,
            autoScroll: true,
            rowNum: 10, //每页显示记录数
            rowList: [10, 20, 100], //可调整每页显示的记录数
            pager: "#endgoodPage", //分页工具栏
            sortname: "seqNo",
            sortorder: "desc",
            loadComplete: function () {
                var rowNum = $(this).jqGrid('getGridParam', 'records');
                if (rowNum <= 0) {
                    if ($(this).parent().children('.norecords').length == 0)
                        $(this).parent().append("<div class=\"norecords\">暂无数据！</div>");
                    $(this).parent().children('.norecords').show();
                }
                else {//如果存在记录，则隐藏提示信息。
                    $(this).parent().children('.norecords').hide();
                }

                $(".ui-jqgrid tr.ui-row-ltr td").css('text-align', 'center');
            }
        });

        $("#materialsList").jqGrid({
            datatype: "json",
            url: $basePath + "/exportB2C/cancelBillMaterials/queryMaterialsList",
            postData: {relateId: '${baseInfo.id}'},
            colNames: ['', '序号', '商品编码', '附加号', '商品名称', '计量单位', '进口总数量', '深加工结转进口数量',
                '产品总耗用量', '内销数量', '复出数量', '料件放弃数量', '边角料数量', '余料结转数量', '料件剩余数量', '企业库存数', '操作'],
            colModel: [
                {name: 'id', index: 'id', hidden: true},
                {name: 'seqNo', index: 'seqNo', width: 40},
                {name: 'goodsNo', index: 'goodsNo'},
                {name: 'addNo', index: 'addNo'},
                {name: 'goodsName', index: 'goodsName'},
                {name: 'unitDisplay', index: 'unitDisplay'},
                {name: 'importQty', index: 'importQty'},
                {name: 'importDeepProcessQty', index: 'importDeepProcessQty'},
                {name: 'prodUseQty', index: 'prodUseQty'},
                {name: 'domesticSaleQty', index: 'domesticSaleQty'},
                {name: 'comebackQty', index: 'comebackQty'},
                {name: 'abandonQty', index: 'abandonQty'},
                {name: 'scrapQty', index: 'scrapQty'},
                {name: 'leftCarryoverQty', index: 'leftCarryoverQty'},
                {name: 'leftQty', index: 'leftQty'},
                {name: 'entStockQty', index: 'entStockQty'},
                {
                    name: 'options',
                    index: 'options',
                    sortable: false,
                    width: 100,
                    hidden: nonEditable,
                    formatter: materialsOptions
                }
            ],
//            caption: "料件列表",
            viewrecords: true, // show the current page, data rang and total records on the toolbar
            height: 'auto',
            autowidth: true,
            shrinkToFit: false,
            autoScroll: true,
            rowNum: 10, //每页显示记录数
            rowList: [10, 20, 100], //可调整每页显示的记录数
            pager: "#materialsPage", //分页工具栏
            sortname: "seqNo",
            sortorder: "desc",
            loadComplete: function () {
                var rowNum = $(this).jqGrid('getGridParam', 'records');
                if (rowNum <= 0) {
                    if ($(this).parent().children('.norecords').length == 0)
                        $(this).parent().append("<div class=\"norecords\">暂无数据！</div>");
                    $(this).parent().children('.norecords').show();
                }
                else {//如果存在记录，则隐藏提示信息。
                    $(this).parent().children('.norecords').hide();
                }

                $(".ui-jqgrid tr.ui-row-ltr td").css('text-align', 'center');
            }
        });

        $("#consumptionList").jqGrid({
            datatype: "json",
            url: $basePath + "/exportB2C/cancelBillConsumption/queryConsumptionList",
            postData: {relateId: '${baseInfo.id}'},
            colNames: ['', '序号', '成品名称', '料件序号', '料件名称', '处理标志', '单耗/净耗', '损耗率%', '非保税料件比例%', '操作'],
            colModel: [
                {name: 'id', index: 'id', hidden: true},
                {name: 'seqNo', index: 'seqNo', width: 40},
                {name: 'goodName', index: 'goodName'},
                {name: 'materialsNo', index: 'materialsNo'},
                {name: 'materialsName', index: 'materialsName'},
                {name: 'dealFlag', index: 'dealFlag'},
                {name: 'netWaste', index: 'netWaste'},
                {name: 'wasteRate', index: 'wasteRate'},
                {name: 'unTaxMaterialsPercent', index: 'unTaxMaterialsPercent'},
                {
                    name: 'options',
                    index: 'options',
                    sortable: false,
                    width: 100,
                    hidden: nonEditable,
                    formatter: consumptionOptions
                }
            ],
//            caption: "单损耗列表",
            viewrecords: true, // show the current page, data rang and total records on the toolbar
            height: 'auto',
            autowidth: true,
            shrinkToFit: false,
            autoScroll: true,
            rowNum: 10, //每页显示记录数
            rowList: [10, 20, 100], //可调整每页显示的记录数
            width: $('body').width(),
            pager: "#consumptionPage", //分页工具栏
            sortname: "seqNo",
            sortorder: "desc",
            loadComplete: function () {
                var rowNum = $(this).jqGrid('getGridParam', 'records');
                if (rowNum <= 0) {
                    if ($(this).parent().children('.norecords').length == 0)
                        $(this).parent().append("<div class=\"norecords\">暂无数据！</div>");
                    $(this).parent().children('.norecords').show();
                }
                else {//如果存在记录，则隐藏提示信息。
                    $(this).parent().children('.norecords').hide();
                }

                $(".ui-jqgrid tr.ui-row-ltr td").css('text-align', 'center');
            }
        });

        if ({"3": "审核通过"}['${sendStatus}']) {
            $("#baseForm input,textarea").attr("disabled", true);
        }

        $(window).resize(function () {
            $("#declareList,#endgoodList,#materialsList,#consumptionList").setGridWidth($(window).width() - 30);
        });

        $("#declareList,#endgoodList,#materialsList,#consumptionList").setGridWidth($(window).width() - 30);

        $.fastinput.load();

        formValidate("baseForm", {
            eBillingNo: {
                required: true,
                maxBytes: 40
            }, entEBillingNo: {
                required: true,
                maxBytes: 40
            }, enterpriseName: {
                required: true,
                maxBytes: 120
            }, decType: {
                required: true
            }, importTotalValue: {
                required: true,
                maxNum: [14, 4],
                isNumber: true
            }, exportTotalValue: {
                required: true,
                maxNum: [14, 4],
                isNumber: true
            }, importTotalDeclareNum: {
                required: true,
                maxNum: [10],
                isNumber: true
            }, exportTotalDeclareNum: {
                required: true,
                maxNum: [10],
                isNumber: true
            }, cancelMaterialsNum: {
                maxNum: [14, 4],
                isNumber: true
            }, cancelEndgoodNum: {
                maxNum: [14, 4],
                isNumber: true
            }, createOperId: {
                maxBytes: 40
            }
        });

        formValidate("declareForm", {
            declNo: {
                required: true,
                maxBytes: 40
            }, declCustomId: {
                required: true
            }, ieFlag: {
                required: true
            }, declDate: {
                required: true
            }, verifyMode: {
                maxBytes: 40
            }
        });

        formValidate("endgoodsForm", {
            seqNo: {
                required: true,
                maxNum: [30]
            }, goodsNo: {
                required: true
            }, goodsName: {
                required: true,
                maxBytes: 120
            }, unit: {
                required: true
            }, exportTotalQty: {
                required: true,
                maxNum: [14, 4],
                isNumber: true
            }, exportDeepProcessQty: {
                maxNum: [14, 4],
                isNumber: true
            }, prodAbandonQty: {
                maxNum: [14, 4],
                isNumber: true
            }, prodReturnImportQty: {
                maxNum: [14, 4],
                isNumber: true
            }, prodReturnExportQty: {
                maxNum: [14, 4],
                isNumber: true
            }, entStockQty: {
                maxNum: [14, 4],
                isNumber: true
            }
        });

        formValidate("materialsForm", {
            seqNo: {
                required: true,
                maxNum: [30]
            }, goodsNo: {
                required: true
            }, goodsName: {
                required: true,
                maxBytes: 120
            }, mUnit: {
                required: true
            }, importQty: {
                required: true,
                maxNum: [14, 4],
                isNumber: true
            }, importDeepProcessQty: {
                maxNum: [14, 4],
                isNumber: true
            }, prodUseQty: {
                maxNum: [14, 4],
                isNumber: true
            }, domesticSaleQty: {
                maxNum: [14, 4],
                isNumber: true
            }, abandonQty: {
                maxNum: [14, 4],
                isNumber: true
            }, scrapQty: {
                maxNum: [14, 4],
                isNumber: true
            }, comebackQty: {
                maxNum: [14, 4],
                isNumber: true
            }, leftCarryoverQty: {
                maxNum: [14, 4],
                isNumber: true
            }, leftQty: {
                maxNum: [14, 4],
                isNumber: true
            }, entStockQty: {
                maxNum: [14, 4],
                isNumber: true
            }
        });

        formValidate("consumptionForm", {
            seqNo: {
                required: true,
                maxNum: [30]
            }, goodName: {
                required: true,
                maxBytes: 120
            }, materialsNo: {
                required: true,
                maxNum: [30]
            }, materialsName: {
                required: true,
                maxBytes: 120
            }, netWaste: {
                maxNum: [14, 4],
                isNumber: true
            }, wasteRate: {
                maxNum: [5, 2],
                max: 100,
                min: 0,
                isNumber: true
            }, unTaxMaterialsPercent: {
                maxNum: [5, 2],
                max: 100,
                min: 0,
                isNumber: true
            }, dealFlag: {
                maxBytes:40
            }
        });
    });

    function save(func, formId) {
        var relateId = $("form[id='baseForm'] input[name='id']").val();
        if (!isValid(formId)) {
            return;
        }

        if (relateId == "") {
            saveBaseInfo(func);
        } else {
            if (typeof func === "function") {
                $("[name='relateId']").val($("form[id='baseForm'] input[name='id']").val());
                func();
            }
        }


        $("[name='relateId']").val($("form[id='baseForm'] input[name='id']").val());
    }

    function saveBaseInfo(callback) {
        if (!isValid("baseForm")) {
            return;
        }

        $.ajax({
            url: $basePath + "/exportB2C/cancelBill/save",
            type: "post",
            data: $("#baseForm").serialize(),
            dataType: "json",
            success: function (data) {
                showOKMessage("保存成功！", "提示信息", null, null);
                $("form[id='baseForm'] input[name='id']").val(data.id);
                $("form[id='baseForm'] input[name='sendStatus']").val(data.sendStatus);
                $("#sendStatusC").text(data.sendStatusDisplay);
                $("input[name='relateId']").val(data.id);

                if (typeof callback === "function") {
                    callback();
                }
            },
            error: function (error) {
                showErrorMessage("操作失败，请及时联系管理员，错误信息：" + error, "错误提示", null, null);
            }
        })
    }

    function reloadDeclareGrid() {
        $._options._reload("declareList", $basePath + "/exportB2C/cancelBillDeclare/queryDeclareList", {relateId: $("[name='id']:eq(0)").val()});
    }

    function reloadEndgoodGrid() {
        $._options._reload("endgoodList", $basePath + "/exportB2C/cancelBillEndgood/queryEndGoodsList", {relateId: $("[name='id']:eq(0)").val()});
    }

    function reloadMaterialsGrid() {
        $._options._reload("materialsList", $basePath + "/exportB2C/cancelBillMaterials/queryMaterialsList", {relateId: $("[name='id']:eq(0)").val()});
    }

    function reloadConsumptionGrid() {
        $._options._reload("consumptionList", $basePath + "/exportB2C/cancelBillConsumption/queryConsumptionList", {relateId: $("[name='id']:eq(0)").val()});
    }

    function saveDeclareInfo() {
        $._options._save($basePath + "/exportB2C/cancelBillDeclare/save", "#declareForm", reloadDeclareGrid);
    }

    function saveEndgoodsInfo() {
        $._options._save($basePath + "/exportB2C/cancelBillEndgood/save", "#endgoodsForm", reloadEndgoodGrid);
    }

    function saveMaterialsInfo() {
        $._options._save($basePath + "/exportB2C/cancelBillMaterials/save", "#materialsForm", reloadMaterialsGrid);
    }

    function saveConsumptionInfo() {
        $._options._save($basePath + "/exportB2C/cancelBillConsumption/save", "#consumptionForm", reloadConsumptionGrid);
    }
</script>
</body>
</html>
